import React, { useState } from 'react';
import useMyReducer from '../../reducer';
import { useNavigate } from 'react-router-dom'

const Index = () => {
    const navigate = useNavigate()
    const { dispatch } = useMyReducer()
    const [cities] = useState(['武汉', '北京', '上海'])
    const handleCity = (val) => {
        dispatch({
            type: "changeCity",
            value: val
        })
        navigate(-1)
    }
    return (
        <div>
            city
            <hr />
            {cities.map(item => {
                return (<button onClick={() => handleCity(item)} key={item}>{item}</button>)
            })}
        </div>
    );
}

export default Index;
